<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * 排课相关Controller
 */
class Class_plan extends MY_Controller {

    function __construct(){
    parent::__construct();

      $parent_id = 6;
      //获取school二级菜单
      $this->load->model('School_manage_menu_model');
      $menu_list = $this->School_manage_menu_model->get_menu_list($this->is_manage,$parent_id);
      // print_r($menu_list);exit;
      $this->smarty->assign("menu_list", $menu_list);

      $this->left_menu_min = array("menu" => "教务管理", "curr" => '/classes', "list" => $menu_list);
      $this->smarty->assign("left_menu_min", $this->left_menu_min);

      $this->smarty->assign("menu", 'classes');

  }



  /**
   * 手动添加课程计划
   * @param [type] $class_id [description]
   */
  public function add_single($class_id)
  {
    $post_data = $this->input->post();
		$this->smarty->assign("class_id", $class_id);

    if($post_data){
      // print_r($post_data['class_hour']);exit;

			$this->load->model('Class_plan_model');
			$result = $this->Class_plan_model->add_single($post_data,$class_id);
			if($result>0){
				print_r('{"result":"0","msg":"success"}');exit;
				// $this->smarty->display("order/student_info_success.html");
				// exit;
	    }
		}


    //班级详情
		$this->load->model('Classo2o_model');
		$class_info = $this->Classo2o_model->get_class_by_id($class_id);
		$this->smarty->assign("class_info", $class_info);

    //获取老师
    $this->load->model('Teachers_model');
    $teachers = $this->Teachers_model->get_teacher_all_by_school($this->user_data['school_id']);
    $this->smarty->assign("teachers", $teachers);

    //获取教室
    $this->load->model('Classo2o_model');
		$room_list = $this->Classo2o_model->get_classroom($this->user_data['school_id']);
		$this->smarty->assign("room_list", $room_list);


    $this->smarty->display("class_plan/add_single.html");
  }

  /**
   * 自动排课
   * @param  [type] $class_id [description]
   * @return [type]           [description]
   */
  public function auto_plan($class_id)
  {
    $post_data = $this->input->post();
		$this->smarty->assign("class_id", $class_id);
    if($post_data){

			$this->load->model('Class_plan_model');
			$result = $this->Class_plan_model->auto_plan($post_data,$class_id);
      // print_r($result);exit;
			if($result>0){
				print_r('{"result":"0","msg":"success"}');exit;
	    }
		}

    //班级详情
		$this->load->model('Classo2o_model');
		$class_info = $this->Classo2o_model->get_class_by_id($class_id);
		$this->smarty->assign("class_info", $class_info);

    //获取老师
    $this->load->model('Teachers_model');
    $teachers = $this->Teachers_model->get_teacher_all_by_school($this->user_data['school_id']);
    $this->smarty->assign("teachers", $teachers);

    //获取教室
    $this->load->model('Classo2o_model');
		$room_list = $this->Classo2o_model->get_classroom($this->user_data['school_id']);
		$this->smarty->assign("room_list", $room_list);
    $this->smarty->display("class_plan/auto_plan.html");
  }


  function plan_auto($class_id){
    $post_data = $this->input->post();
    $this->smarty->assign("class_id", $class_id);
    if($post_data){

      $this->load->model('Class_plan_model');
      $result = $this->Class_plan_model->auto_plan($post_data,$class_id);
      // print_r($result);exit;
      if($result>0){
        header("Location:/classes/plan/".$class_id);exit;
      }
    }

    //班级详情
    $this->load->model('Classo2o_model');
    $class_info = $this->Classo2o_model->get_class_by_id($class_id);
    $this->smarty->assign("class_info", $class_info);

    //获取老师
    $this->load->model('Teachers_model');
    $teachers = $this->Teachers_model->get_teacher_all_by_school($this->user_data['school_id']);
    $this->smarty->assign("teachers", $teachers);

    //获取教室
    $this->load->model('Classo2o_model');
    $room_list = $this->Classo2o_model->get_classroom_by_campus($class_info['campus']);
    $this->smarty->assign("room_list", $room_list);
    $this->smarty->display("class_plan/plan_auto.html");
  }


}
